package com.hxkj.controller;

import com.github.pagehelper.PageInfo;
import com.hxkj.domain.po.UserArticle;
import com.hxkj.service.ArticleCollectionService;
import com.platform.common.dispatcher.util.ResultStructUtils;
import com.platform.common.domain.result.ParameterDataStruct;
import com.platform.common.domain.result.ResultMessageStruct;
import com.platform.common.domain.result.ResultPageStruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.Callable;

/**
 * created by chenfangzhou on 2018/8/13
 */
@RestController
@RequestMapping("/article")
public class ArticleCollectionController {

    @Autowired
    private ArticleCollectionService articleCollectionService;


    /**
     * 收藏文章
     */
    @RequestMapping(value = "/collectArticle", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
    public Callable<ResultMessageStruct> collectArticle(@RequestBody UserArticle userArticle) throws Exception {
        return () -> articleCollectionService.collectArticle(userArticle);
    }

    /**
     * 取消收藏文章
     */
    @RequestMapping(value = "/cancelCollectArticle", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
    public Callable<ResultMessageStruct> cancelCollectArticle(@RequestBody UserArticle userArticle) throws Exception {
        return () -> articleCollectionService.cancelCollectArticle(userArticle);
    }

    @RequestMapping(value = "/ifCollectArticle")
    public Callable<Integer> ifCollectArticle(@RequestBody UserArticle userArticle) throws Exception{
        return () -> articleCollectionService.ifCollectArticle(userArticle);
    }

    /**
     * 获取收藏文章列表
     */
    @RequestMapping(value = "/getCollectionList", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
    public Callable<PageInfo<UserArticle>> getCollectionList(@RequestBody ParameterDataStruct<UserArticle> parameterDataStruct) throws Exception {
        return () -> articleCollectionService.getCollectionList(parameterDataStruct.getData() == null ? new UserArticle() : parameterDataStruct.getData(), parameterDataStruct.getPageTo());
    }
}
